<?php
/**
 * 金库模块
 * 
 * @version $Id$
 */

class Module_money
{
	/**
	 * 构造函数
	 */
	function __construct() {
		
	}

	
	function index() {
		$uin = SessionInfo('uin');
		
		$smarty = loadSmarty();
		
		// 获取金库
		loadLib('Money');
		$money = Money::get( $uin );
		$money_str = Money::toString($money);
		
		$money_capacity = Money::getCapacity( $money['level'] );
		$money_capacity_str = Money::toString($money_capacity);
		
		$smarty->assign('money' , $money);
		$smarty->assign('money_str' , $money_str);
		$smarty->assign('money_capacity' , $money_capacity);
		$smarty->assign('money_capacity_str' , $money_capacity_str);
		
		return $smarty->fetch('money/index.tpl.php');
	}
	
	/**
	 * 金币排行榜
	 */
	function top() {
		$smarty = loadSmarty();
		
		// 获取金库
		loadLib('Money');
		$list = Money::getTopList();
		
		$uin_arr = array();
		foreach($list as $row) {
			$uin_arr[] = $row['uin'];
		}
		
		loadLib('User');
		$uin_arr_info = User::getBaseInfo($uin_arr);
		foreach($list as $k => $row) {
			$list_uin = $row['uin'];
			$list[$k]['name'] = isset($uin_arr_info[$list_uin]) ? $uin_arr_info[$list_uin]['name'] : '';
			$list[$k]['sex'] = isset($uin_arr_info[$list_uin]) ? $uin_arr_info[$list_uin]['sex'] : '';
			$list[$k]['money_str'] = Money::toString( array('gold' => $row['gold']) );
		}
		
		$smarty->assign('list' , $list);
		
		return $smarty->fetch('money/top.tpl.php');
	}
	
	/**
	 * 钱币交易
	 */
	function exchange() {
		$uin = SessionInfo('uin');
		
		$smarty = loadSmarty();
		
		// 获取金库
		loadLib('Money');
		$money = Money::get( $uin );
		$money_str = Money::toString($money);
		
		$money_capacity = Money::getCapacity( $money['level'] );
		$money_capacity_str = Money::toString($money_capacity);
		
		$smarty->assign('money' , $money);
		$smarty->assign('money_str' , $money_str);
		$smarty->assign('money_capacity' , $money_capacity);
		$smarty->assign('money_capacity_str' , $money_capacity_str);
		
		return $smarty->fetch('money/exchange.tpl.php');
	}
	
	/**
	 * 扩建
	 */
	function upgrade() {
		$uin = SessionInfo('uin');
		
		$smarty = loadSmarty();
		
		// 获取金库
		loadLib('Money');
		$money = Money::get( $uin );
		$money_str = Money::toString($money);
		
		$money_capacity = Money::getCapacity( $money['level'] );
		
		$money_capacity_str = Money::toString($money_capacity);
		
		$smarty->assign('money' , $money);
		$smarty->assign('money_str' , $money_str);
		$smarty->assign('money_capacity' , $money_capacity);
		$smarty->assign('money_capacity_str' , $money_capacity_str);
		
		return $smarty->fetch('money/upgrade.tpl.php');
	}
	
	/**
	 * 钱币交易
	 */
	function intro() {
		$smarty = loadSmarty();
		
		return $smarty->fetch('money/intro.tpl.php');
	}
	
}

# end of script
